\begin{verbatim}
//
// --Appendix of Magma Code--
//
// Define shorthand notation:
ZZ := Integers(); 
I2S := IntegerToString; 
function EK(K,M)
    X := [ M[i]+K[i] : i in [1..4] ];
    return [ X[1]+X[3], X[2]+X[4], X[2]+X[3], X[1]+X[4] ];
end function;

Kbits := [GF(2)|1,0,1,1];
Mbits := [GF(2) |
    1,1,0,1,0,1,1,0,
    1,1,1,0,0,1,1,1,
    0,0,1,0,0,1,0,0,
    0,1,0,0,1,0,0,0
];

// ECB Mode Computation
ECBbits := &cat[EK(Kbits,Mbits[[4*i+1..4*i+4]]) : i in [0..7]];  
"ECB mode:", &cat[ I2S(ZZ!x) : x in ECBbits ];

// CBC Mode Computation
Cbits := [GF(2)|1,0,0,1];
CBCbits := [GF(2)|];
for i in [0..7] do
    Cbits := EK(Kbits,[ Cbits[j]+Mbits[4*i+j] : j in [1..4] ]);
    CBCbits cat:= Cbits;
end for;    
"CBC mode:", &cat[ I2S(ZZ!x) : x in CBCbits ];

// CFB Mode Computation
Ibits := [GF(2)|1,0,0,1];
CFBbits := [GF(2)|];
for j in [1..32] do
    Append(~CFBbits,Mbits[j]+EK(Kbits,Ibits)[1]);
    Ibits := Ibits[[2..4]] cat [CFBbits[j]];
end for;    
"CFB mode:", &cat[ I2S(ZZ!x) : x in CFBbits ];
\end{verbatim}
